
<link rel="stylesheet" href="jquery/easyui/themes/default/easyui.css">
<link rel="stylesheet" href="jquery/easyui/themes/icon.css">
<body>
<div style="width: 100%;height: 98%">
	<select id="materialDeptId"
		style="height:31px">
		<option value="">所有部门</option>
	</select>
    <table id="easyui_datagrid_source_fac" style="border:1px solid blue" >

    </table>
    <span id="isUpdate"></span>
</div>


<script src="https://upload.shinehao.com.cn/20180816150739jquery-1.8.3.min.js"></script>
<script src="https://upload.shinehao.com.cn/20180816145716jquery.easyui.min.js"></script>
<script src="https://upload.shinehao.com.cn/20180816151727easyui-lang-zh_CN.js"></script>
<script>
var material_source_type = window.parent.getMyUrlQueryString(window.location.href,"material_source_type");
var ev = window.parent.getMyUrlQueryString(window.location.href,"ev");
var father = window.parent.getMyUrlQueryString(window.location.href,"father");
var isreadcolor = window.parent.getMyUrlQueryString(window.location.href,"isreadcolor");
var cpLock = false;
var initCode = $(window.parent.document).find("#"+father).find("[name='order_s_input_material_code']").val();
$(function(){
	if(window.parent.basicDataFixed.isUpdate!=1){
		$("#isUpdate").text("支持可输可选择");
		$("#isUpdate").css({"font-size":"3px","color":"red"})
	}else{
		$("#isUpdate").text("仅支持可选择");
		$("#isUpdate").css({"font-size":"3px","color":"red"})
	}
    $("body").bind("click",function(){
        $('#easyui_datagrid_source_fac').combogrid("showPanel");
    })
    $('#easyui_datagrid_source_fac').combogrid({
        mode:"remote",
        url:window.parent.serverUrl+"/createOrder/getFactoryTabChildList",
        queryParams: {
            material_factory: 1,
            material_type: material_source_type,
            isReadColor:isreadcolor,
            q:$(window.parent.document).find("#"+father).find("[name='order_s_input_material_code']").val().trim()
        },
        idField: 'color',
        textField: 'colorDescription',
        columns:[[
            {field:'color',title:'色号',hidden:false},
            {field:'colorDescription',title:'颜色描述',hidden:false},
            {field:'materialCode',title:'物料代码',hidden:true},
            {field:'materialType',title:'物料类型',hidden:true},
            {field:'model',title:'规格型号'},
            {field:'materialName',title:'物料名称'},
            {field:'defaultWarehouse',title:'所属',hidden:true},
            {field:'providerName',title:'供应商'},
            {field:'material',title:'材质'},
            {field:'unitPrice',title:'单价',hidden:true},
            {field:'unit',title:'单位'},
            {field:'providerNo',title:'供方编号'},
            {field:'materialCount',title:'库存数'},
            {field:'useableMaterialCount',title:'可用库存数'}
        ]],
        height:"10%",
        nowrap: false,
        width:"50%",
        panelWidth:"100%",
        panelHeight:"88%",
        //rownumbers:true,
        fitColumns:true,
        pagination:true,
        //pageSize: 10,
        pageList: [10,20,50,100],
        layout:['links'],
        loadMsg:"加载中,请等待...",
        singleSelect:true,
        align:"center",
        //toolbar: '#easyui_datagrid_source_fac_tool',
        loadFilter: function(data){
          return data.data;  
        },
        keyHandler: {
            enter: function(e){
                //console.info($('#easyui_datagrid_source_fac').combogrid("getValue"));
                //console.info($('#easyui_datagrid_source_fac').combogrid("getText"));
                var rows = $('#easyui_datagrid_source_fac').combogrid('grid').datagrid('getData').rows;	// get datagrid object
                /* if(rows.length>0){
                    filldata(rows[0],"")
                }else{
                    filldata("",$('#easyui_datagrid_source_fac').combogrid("getText"))
                } */
                filldata("",$('#easyui_datagrid_source_fac').combogrid("getText"))
                $('#easyui_datagrid_source_fac').combogrid("showPanel");
            },
            query: function (q) {
            	setTimeout(function(){
	            	if(!cpLock){
	                	$('#easyui_datagrid_source_fac').combogrid("grid").datagrid("reload", {
	                        material_factory: 1,
	                        material_type: material_source_type,
	                        materialDeptId:$("#materialDeptId").val(),
	                        'q': q,
	                    });
	                    $('#easyui_datagrid_source_fac').combogrid("setValue",q);
	                }
            	},0);
            },
            up: function (e) {
                
            },
            down: function (e) {
                
            }
        },
        onLoadSuccess:function(data){
        	$(".datagrid-pager").pagination({layout:['links']});
        	//如果订单是没有数据 新订单则获取不到isreadcolor，这里是为了补充
        	if(data.total > 0 && isreadcolor=="") {
        		isreadcolor=data.rows[0].isReadColor;
        	}
            if(data.total > 0) {
                $("input[type='text']").focus();
                return;
            }  
            //$(this).datagrid('appendRow', { color: '<div style="text-align:center;color:red">没有相关记录！</div>' }).datagrid('mergeCells', { index: 0, field: 'color', colspan: 3});  
            $("input[type='text']").focus();
            $('#easyui_datagrid_source_fac').combogrid("showPanel");
            
            $("input[type='text']").on('compositionstart', function () {
                cpLock = true;
            });
            $("input[type='text']").on('compositionend', function () {
                cpLock = false;
            });
        },
        /*onSelect:function(index,row){
            console.info(row);
            var self = $(window.parent.document).find("["+dom.split(":")[0]+"='"+dom.split(":")[1]+"']");
            //console.info("myid:"+$(self).attr("myid")+":"+$(self).length+":"+"'"+dom.split(":")[0]+"'");
            //console.info("id:"+$(self).attr("id")+":"+$(self).length+":"+"'"+dom.split(":")[0]+"'");
            //console.info($(self).attr("'"+dom.split(":")[0]+"'"));
            //物料代码 色号 颜色描述 规格 填充
            
            $("input[type='text']").focus();
            $('#easyui_datagrid_source_fac').combogrid("showPanel");
        },*/
        onClickRow:function(index,row){
            filldata(row,"");
            $("input[type='text']").focus();
            $('#easyui_datagrid_source_fac').combogrid("showPanel");
        }
    });
    $('#easyui_datagrid_source_fac').combogrid("showPanel");
    $("input[type='text']").focus();
    setTimeout(function(){
    	if(initCode!=null&&initCode.trim().length>0){
    		$("input[type='text']").val($(window.parent.document).find("#"+father).find("[name='"+ev+"']").val())
    	}
    },500)
})
    
function filldata(data,text){
    if(data!=null&&data!=""){
        $(window.parent.document).find("#"+father).find("[name='"+ev+"']").val(data.model);
        $(window.parent.document).find("#"+father).find("[name='order_s_input_material_code']").val(data.materialCode);
        $(window.parent.document).find("#"+father).find("[name='order_s_input_val_quality_type']").val(data.material);
        $(window.parent.document).find("#"+father).find("[name='order_s_input_val_provider_name']").val(data.providerName);
    }
    if(text!=null&&text!=""&&window.parent.basicDataFixed.isUpdate!=1){
        $(window.parent.document).find("#"+father).find("[name='"+ev+"']").val(text);
        if(isreadcolor==2&&(ev.indexOf("material_color")>-1||ev.indexOf("material_description")>-1)){
        	//如果物料不读颜色的并且正在修改色号色号描述的不修改物料代码
        }else{
        	$(window.parent.document).find("#"+father).find("[name='order_s_input_material_code']").val(" ");
        }
    }
    
    window.parent.table_source_factory_input.destroydialog();
    
}

$(function(){
	$.ajax({
        type: 'POST',
        url: window.parent.serverUrl+"/createOrder/getCompanyMaterialDeptInfo",
        data: {},
        success: function(data){
         	if(data.data.length>0){
         		$("#materialDeptId").empty();
     			$("#materialDeptId").append('<option value="">所有部门</option>')
         		for(var i=0;i<data.data.length;i++){
         			$("#materialDeptId").append('<option value="'+data.data[i].materialDeptId+'">'+data.data[i].materialDeptName+'</option>')
         		}
         	}
        }
	});
	$("#materialDeptId").bind("change",function(){
		$('#easyui_datagrid_source_fac').combogrid("grid").datagrid("reload", {
            material_factory: 1,
            material_type: material_source_type,
            materialDeptId:$("#materialDeptId").val()
        });
	})
})
</script>
</body>


























